package cn.ppwx.crm.modules.sys.utils;

import java.util.Map;

import org.springframework.util.StringUtils;



public class MapKit {


    //获取MAP的值
    public static <K,V,T>  Object  getValueFromMap(Map<K, V> map,T key){

        if(map==null){
            return null;
        }

        if(!map.containsKey(key)){
            return null;
        }

        if(StringUtils.isEmpty(map.get(key))){
            return null;
        }
        return map.get(key);
    }


    public static <K,V,T>  boolean  hasNotNullValue(Map<K, V> map,T key){

        if(!map.containsKey(key)){
            return false;
        }

        if(map.get(key)==null){
            return false;
        }

        if(map.get(key).toString().length()==0){
            return false;
        }

        return true;

    }


    //获取String值
    public static  <K,V,T> String  getStrValueFromMap(Map<K, V> map,T key){

        Object obj = getValueFromMap(map,key);

        if(obj==null){
            return "";
        }

        return obj.toString();
    }

    //获取int值
    public static  <K,V,T> int  getIntValueFromMap(Map<K, V> map,T key){

        Object obj = getValueFromMap(map,key);

        if(obj==null){
            return 0;
        }

        try {
            return Integer.valueOf(obj.toString()).intValue();
        }catch(Exception e){

        }
        return  0;

    }
    
    
    //获取long值
    public static  <K,V,T> long  getLongValueFromMap(Map<K, V> map,T key){

        Object obj = getValueFromMap(map,key);

        if(obj==null){
            return 0;
        }

        try {
            return Long.valueOf(obj.toString()).intValue();
        }catch(Exception e){

        }
        return  0;

    }


    //获取Double值
    public static  <K,V,T> double  getDoubleValueFromMap(Map<K, V> map,T key){

        Object obj = getValueFromMap(map,key);

        if(obj==null){
            return 0;
        }

        try {
            return Double.valueOf(obj.toString());
        }catch(Exception e){

        }
        return  0;
    }

}